﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using System.Collections.Generic;

#endregion

namespace ScrumTable.Common.EventHandling
{
    /// <summary>
    /// Represents an event handler which is used in conjunction
    /// with the TryFire method of the IDelegateHandlerCollection interface.
    /// </summary>
    /// <typeparam name="T">Type of the delegate to fire.</typeparam>
    /// <param name="eventHandler">The concrete event handler instance.</param>
    public delegate void FireEventHandler<T>(T eventHandler);

    /// <summary>
    /// Specifies an interface for event handler lists.
    /// </summary>
    /// <typeparam name="T">Type of the delegate to use.</typeparam>
    public interface IDelegateHandlerCollection<T> : IDisposable
        where T : class
    {
        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Checks whether the event with the given key has elements to fire.
        /// </summary>
        /// <param name="key">Key of the delegate to check.</param>
        /// <returns>Returns true if the corresponding event has elements to fire.</returns>
        bool HasEvents(string key);

        /// <summary>
        /// Adds a new delegate to the current list.
        /// </summary>
        /// <param name="key">Key of the delegate to add.</param>
        /// <param name="toAdd">Delegate (method pointer) to add.</param>
        void Add(string key, T toAdd);

        /// <summary>
        /// Removes a delegate form the current list.
        /// </summary>
        /// <param name="key">Key of the delegate to remove.</param>
        /// <param name="toRemove">Delegate (method pointer) to remove.</param>
        bool Remove(string key, T toRemove);

        /// <summary>
        /// Tries to fire a multicast delegate as an event.
        /// </summary>
        /// <param name="key">Key of the delegate to fire.</param>
        /// <param name="sender">Specifies the sender object which should be passed to the delegate.</param>
        /// <param name="args">Specifies the event argument object which should be passed to the delegate.</param>
        /// <returns>Returns true if the multicast delegate could be fired otherwise false.</returns>
        bool TryFire(string key, object sender, EventArgs args);

        /// <summary>
        /// Fires a multicast delegate as an event.
        /// </summary>
        /// <param name="key">Key of the delegate to fire.</param>
        /// <param name="sender">Specifies the sender object which should be passed to the delegate.</param>
        /// <param name="args">Specifies the event argument object which should be passed to the delegate.</param>
        /// <returns>
        /// Returns true if the multicast delegate could be fired otherwise false.
        /// </returns>
        void Fire(string key, object sender, EventArgs args);

        #endregion
    }
}
